package cn.kgc.vue.controller;

import cn.kgc.vue.annotation.LogAnnotation;
import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import cn.kgc.vue.entity.Dept;
import cn.kgc.vue.service.DeptService;
import cn.kgc.vue.enums.OperationType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("dept")
@Api(tags = "部门模块")
public class DeptController {
    @Resource
    private DeptService deptService;

    @GetMapping("list")
    @ApiOperation("部门列表")
    public ResponseResult deptList(){
        List<Dept> list = deptService.list();
        return ResponseResult.success().data("deptList", list);
    }

    @ApiOperation("部门分页")
    @PostMapping("page")
    public ResponseResult deptPage(@RequestBody QueryCondition<Dept> queryCondition){

        return deptService.deptPage(queryCondition);
    }


    @LogAnnotation(model="部门模块",operation= OperationType.ADD)
    @RequiresPermissions(value = {"sys:dept:update", "sys:dept:add"}, logical = Logical.OR)
    @ApiOperation("部门新增/修改")
    @PostMapping("addOrUpdate")
    public ResponseResult addOrUpdateDept(@RequestBody Dept dept){

        deptService.saveOrUpdate(dept);
        return ResponseResult.success();
    }

    @LogAnnotation(model="部门模块",operation= OperationType.DELETE)
    @RequiresPermissions("sys:dept:delete")
    @ApiOperation("删除部门")
    @DeleteMapping("delete/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){

        return deptService.delete(id);
    }

}
